﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.CompilerServices;

namespace Benchmark_System {
    public class Job {

        public enum JobState {QUEUED, STOPPED, RUNNING, FAILED }

        public int delayed {
            set;
            get;
        }

        int _cpu;
        public int Cpu {
            private set {
                if (value <= 10 && value > 0) {
                    this._cpu = value;
                }
                else {
                    throw new ArgumentOutOfRangeException();
                }
            }
            get {
                return this._cpu;
            }
        }

        double _expectedRuntime;
        public double ExpectedRuntime {
            private set {
                if (value <= 5 && value >= 0.1) {
                    this._expectedRuntime = value;
                }
                else {
                    throw new ArgumentOutOfRangeException();
                }
            }
            get {
                return Math.Round(this._expectedRuntime,1);
            }
        }

        public JobState State {
            set;
            get;
        }

        public long TimeStamp {
            set;
            get;
        }

        public Owner owner {
            get;
            set;
        }

        public int id {
            get;
            set;
        }

        /// <summary>
        /// Defines a job
        /// </summary>
        /// <param name="Cpu">Number of CPUs</param>
        /// <param name="ExpectedRuntime">Job runtime</param>
        /// <param name="State">Which state the job has</param>
        /// <param name="Del">The delegate function</param>
        public Job(int Cpu, double ExpectedRuntime, JobState State, Func<String[], string> Del) {
            this.Cpu = Cpu;
            this.ExpectedRuntime = ExpectedRuntime;
            this.State = State;
            this.TimeStamp = Scheduler.time.ElapsedTicks;
            //assign the delegate
            Process = Del;
        }

        /// <summary>
        /// Delegate process method
        /// </summary>
        internal Func<String[], string> Process;

    }
}
